package service

import (
	"context"
	"videosS_rpc/basic/config"
	__ "videosS_rpc/basic/proto"
	"videosS_rpc/handler/model"
)

func (s *Server) CollectAdd(_ context.Context, in *__.CollectAddReq) (*__.CollectAddResp, error) {

	video := model.Collect{

		VideoId:      int(in.VideoId),
		UserId:       int(in.UserId),
		CollectCount: int(in.CollectCount),
	}
	err := video.CollectAdd(config.DB)
	if err != nil {
		return nil, err
	}
	return &__.CollectAddResp{
		CollectId: int64(video.ID),
	}, nil
}

func (s *Server) CollectList(_ context.Context, in *__.CollectListReq) (*__.CollectListResp, error) {

	video := model.Collect{}
	list, err := video.CollectList(config.DB)
	if err != nil {
		return nil, err
	}
	return &__.CollectListResp{
		List: list,
	}, nil
}

func (s *Server) LikeAdd(_ context.Context, in *__.CollectAddReq) (*__.CollectAddResp, error) {

	video := model.Collect{

		VideoId:      int(in.VideoId),
		UserId:       int(in.UserId),
		CollectCount: int(in.CollectCount),
	}
	err := video.CollectAdd(config.DB)
	if err != nil {
		return nil, err
	}
	return &__.CollectAddResp{
		CollectId: int64(video.ID),
	}, nil
}
